﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace TomNet.AspNetCore
{
    public static class CorsApplicationBuilderExtensions
    {
        /// <summary>
        /// 启用跨域策略
        /// </summary>
        public static void UseCross(this IApplicationBuilder app)
        {
            var _options = app.ApplicationServices.GetTomNetOptions();
            if (_options.Cross == null)
            {
                return;
            }
            if (_options.Cross.CrossType != Entity.CrossType.Reject)
            {
                app.UseCors(_options.Cross.PolicyName);
            }
        }
    }
}
